﻿import QtQuick 2.0

Image {
    id: options
    source: "qrc:/img/img/menuBg.png"
    scale: 0

    Keys.onBackPressed: {
        options.scale = 0
        bStartGame = true
        rectBgMain.focus = true
    }

    Behavior on scale {
        SpringAnimation{
            damping: 0.9
            spring: 5
        }
    }

    signal clickButtons(var value)

    onClickButtons: {
        if(value == 1){
            //resume
            options.scale = 0
            bStartGame = true
            rectBgMain.focus = true
        }
        else if(value == 2){
            //restart
            options.scale = 0
            score = 0
            for(var i=0 in snake.items){
                var obj = snake.items[i]
                obj.destroy()
            }
            snake.items.length = 0

            snake.head.isShunYi = true
            snake.head.x = (window.width-snake.head.width)/2
            snake.head.y = (window.height-snake.head.height)/2
            snake.head.isShunYi = false
            snake.rotationHead.angle = 0
            bStartGame = true

            rectBgMain.focus = true
        }
        else if(value == 3){
            //ranking
            rankingBg.scale = 1
            rankingBg.focus = true
        }
        else{
            //exit
            Qt.quit()
        }
    }

    Column{
        anchors.horizontalCenter: parent.horizontalCenter
        y: 75
        spacing: 10
        width: img.width
        height: img.height*4+spacing*3

        Image{
            id: img
            source: "qrc:/img/img/option1.png"
            MouseArea{
                anchors.fill: parent
                onClicked: clickButtons(1)
            }
        }
        Image{
            source: "qrc:/img/img/option2.png"
            MouseArea{
                anchors.fill: parent
                onClicked: clickButtons(2)
            }
        }
        Image{
            source: "qrc:/img/img/option3.png"
            MouseArea{
                anchors.fill: parent
                onClicked: clickButtons(3)
            }
        }
        Image{
            source: "qrc:/img/img/option4.png"
            MouseArea{
                anchors.fill: parent
                onClicked: clickButtons(4)
            }
        }
    }


    Image{
        id: rankingBg
        source: "qrc:/img/img/rankingBg.png"
        scale: 0
        visible: rankingBg.scale==0?false:true

        Keys.onBackPressed: {
            rankingBg.scale = 0
            options.focus = true
        }

        Behavior on scale {
            SpringAnimation{
                damping: 0.9
                spring: 5
            }
        }

        transform: Rotation{
            id: rotation
            axis.x: 0
            axis.y: 0
            axis.z: 1
            origin.x: rankingBg.width/2
            origin.y: rankingBg.height/2
            angle: 30
        }

        Text{
            id: textMax
            anchors.centerIn: parent
            text: "最大分数：" + window.maxScore
            font.pointSize: 10
            color: "white"
        }
    }
}

